package com.ttg.web.manage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;

@Configuration
public class HttpRequestExample {

    @Autowired
    private  RestTemplate restTemplate;


    public String sendGetRequest(String url){
        return restTemplate.getForObject(url,String.class);
    }

    public String sendPostRequest(String url,Object request,String openId){
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("OPEN_ID",openId);
        httpHeaders.add("Content-Type","application/json");
        HttpEntity http = new HttpEntity<>(request,httpHeaders);
        return restTemplate.postForObject(url,http,String.class);
    }

    public String sendPostRequestToCoupon(String url,Object request,String eopId){
        HttpHeaders httpHeaders = new HttpHeaders();
//        httpHeaders.add("Accept-Encoding","gzip, deflate, br");
        httpHeaders.add("Content-Type","application/x-www-form-urlencoded");
        HttpEntity http = new HttpEntity<>(request,httpHeaders);
        return restTemplate.postForObject(url,http,String.class);
    }
}
